package top.xia17.plugins.fast.common.security;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.stereotype.Service;

import java.util.Arrays;

/**
 * 权限检测
 * @author xia17
 * @date 2020/8/6 16:32
 */
@Service("pc")
@ConditionalOnMissingBean(name = "pc")
public class PermissionCheck {


    /**
     * 包含所有
     * @param permissions 权限信息
     * @return /
     */
    public Boolean hasAll(String... permissions){
        return Arrays.stream(permissions)
                .allMatch(SecUtil.getAuthorityList()::contains);
    }

    /**
     * 包含一个
     * @param permissions 权限信息
     * @return /
     */
    public Boolean hasOne(String... permissions){
        return Arrays.stream(permissions)
                .anyMatch(SecUtil.getAuthorityList()::contains);
    }


}
